import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:ty_smart_watch/bean/alarm_bean.dart';
import 'package:ty_smart_watch/common/function_id.dart';
import 'package:ty_smart_watch/page/watch_setting_page/child_setting_page/watch_sos_setting_page.dart';
import 'package:ty_smart_watch/page/watch_setting_page/watch_setting_type.dart';
import 'package:ty_smart_watch/route/routes.dart';

import '../../utils/Log.dart';

class WatchSettingPage extends StatefulWidget {
  const WatchSettingPage({super.key});

  @override
  State<WatchSettingPage> createState() => _WatchSettingPageState();
}

class _WatchSettingPageState extends State<WatchSettingPage> {
  int index = 0;
  late List<WatchSettingBean> list;
  String title = "";
  String mac = "";

  @override
  void initState() {
    super.initState();
    index = Get.arguments["index"];
    mac = Get.arguments["mac"];
    WatchSettingType type = WatchSettingType();
    list = type.getList(index);
    title = type.getTitle(index);
    Log.d("页面收到的数据：$index > $title > $mac");
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        leading: IconButton(
          icon: const Icon(Icons.arrow_back_ios),
          onPressed: () {
            Get.back();
          },
        ),
        title: Text(title),
        centerTitle: true,
      ),
      body: ListView.builder(
        itemCount: list.length,
        itemBuilder: (BuildContext context, int index) {
          final item = list[index];
          return Container(
            margin: const EdgeInsets.fromLTRB(10, 10, 10, 0),
            padding: const EdgeInsets.symmetric(horizontal: 10),
            decoration: const BoxDecoration(
                border: Border(bottom: BorderSide(width: 1, color: Color(0xffe5e5e5)))),
            child: ListTile(
              splashColor: Colors.transparent,
              onTap: () {
                Log.d('点击了 ${item.name}');
                naviTo(item.id);
              },
              leading: Image.asset(
                item.imgUrl,
                width: 32,
                height: 32,
              ),
              title: Text(item.name),
              trailing: const Icon(
                Icons.arrow_forward_ios,
                // item.trailing,
                size: 14,
                color: Colors.grey,
              ),
              contentPadding: const EdgeInsets.symmetric(vertical: 2),
            ),
          );
        },
      ),
    );
  }

  /// radioGroupSetting : BRIGHTEN_SCREEN_TIME
  /// SHAKE
  /// HAND_BRIGHTEN_SCREEN
  /// HOUR_TYPE
  /// LANGUAGE
  /// ANTI_LOST
  /// INCH_TYPE
  /// TEMPERATURE_TYPE
  ///
  ///
  ///
  void naviTo(int id) {
    Log.d("点击了：$id");
    // Get.toNamed(Routes.watchRadioGroupSettingPage, arguments: {"id": id, "mac": mac});
    switch (id) {
      case BRIGHTEN_SCREEN_TIME:
      case LANGUAGE:
      case HOUR_TYPE:
      case ANTI_LOST:
      case INCH_TYPE:
      case TEMPERATURE_TYPE:
      case SHAKE:
        Get.toNamed(Routes.watchRadioGroupSettingPage, arguments: {"id": id, "mac": mac});
        break;
      case HAND_BRIGHTEN_SCREEN:
      case DRINK_REMIND:
      case LONG_SIT:
      case TIME_HEART:
      case TIMING_BODY_TEMPERATURE:
        Get.toNamed(Routes.watchTimeRangeSettingPage, arguments: {"id": id, "mac": mac});
        break;
      case PERIOD:
        Get.toNamed(Routes.watchPeriodSettingPage, arguments: {"id": id, "mac": mac});
        break;
      case MEDICINE_REMIND:
        Get.toNamed(Routes.watchMedicineSettingPage, arguments: {"id": id, "mac": mac});
        break;
      case STEP_TARGET:
        Get.toNamed(Routes.watchStepTargetPage, arguments: {"id": id, "mac": mac});
        break;
      case DO_NOT_DISTURB:
        Get.toNamed(Routes.watchDoNotDisturbPage, arguments: {"id": id, "mac": mac});
        break;
      case SOS:
        Get.toNamed(Routes.watchSosSettingPage, arguments: {"id": id, "mac": mac});
        break;
      case ALARM:
        Get.toNamed(Routes.watchAlarmSettingPage, arguments: {"id": id, "mac": mac});
        break;
      // case 0x0:
      // case 0x0:
      // case 0x0:
      // case 0x0:
      // case 0x0:
      // case 0x0:
      // case 0x0:
      // case 0x0:
      // case 0x0:
      // case 0x0:
      // case 0x0:
      // case 0x0:
      // case 0x0:
      // case 0x0:
      // case 0x0:
      // case 0x0:
    }
  }
}
